<?php
	include('connect.php');
	// SELECT ADVERT
	$sql = "SELECT * FROM ADVERTISEMENTS WHERE DISPLAYS > 0 ORDER BY RAND() LIMIT 0,1;";
	$result = mysql_query($sql);
	if(!$result) die("<br />ERROR535 on:<br/><pre>$sql<pre><br />SQL Command Error: " . mysql_error());
	if (mysql_num_rows($result) >= 1){
		$ADTID = mysql_result($result, 0, 'ADTID');
		$LINE1 = mysql_result($result, 0, 'LINE1');
		$LINE2 = mysql_result($result, 0, 'LINE2');
		$LINE3_URL = mysql_result($result, 0, 'LINE3_URL');

		// UPDATE VIEW NUMBER	
		$sql = "UPDATE ADVERTISEMENTS SET DISPLAYS = DISPLAYS - 1 WHERE ADTID = $ADTID;";
		$result = mysql_query($sql);
		if(!$result) die("<br />ERROR535 on:<br/><pre>$sql<pre><br />SQL Command Error: " . mysql_error());

echo <<<_END

		<a href=$LINE3_URL>
		<center>
		<table>
		<tr><td><center>$LINE1</center></td></tr>
		<tr><td><h2><center>$LINE2</center></h2></td></tr>
		</table>
		</center>
		</a>

_END;
}
	include('disconnect.php');

?>
